package cn.lyq.card.utils

import okhttp3.MediaType.Companion.toMediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File


object RetrofitUtils {

    fun buildBody(map: Map<String, Any>, files: Array<File>): MultipartBody {
        val builder = MultipartBody.Builder()
            .setType(MultipartBody.FORM)

        map.forEach {
            builder.addFormDataPart(it.key, it.value.toString())
        }
        files.forEach {
            builder.addFormDataPart("image", it.name, it.asRequestBody("image/png".toMediaType()))
        }
        return builder.build()
    }

}
